-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add validate(query:) method to Validatable protocol #2419
Conversation
…le protocol for validating decoded query parameters.
@odanylewycz nice first-time PR! I've tidied up the comment a bit to use code formatting. Would you mind adding a test or two for the validation stuff? |
@0xTim Thanks for the suggestion! I forgot to do it in the first place. I have gone ahead and added those tests as you requested. I reverted the prior commit because I misspelled "decoding", it was gonna bother me. Let me know if there is anything else I should add! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, thanks! I'm interested for your thoughts about the query
label. Otherwise this is good to go.
… Added old method to Deprecations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks!
These changes are now available in 4.22.0 |
@odanylewycz would you be open to submitting a PR to update https://github.com/vapor/docs/blob/master/4.0/docs/validation.md#validating-request with the new APIs added here? |
@tanner0101 Certainly, it would be my pleasure! I'll get right on it. |
Made the PR, let me know over on that PR if I need to change anything! |
Adds
validate(query:)
method toValidatable
protocol for validating decoded query parameters (#2419).Previously, you could only validate the content that came from the request body. Now, this addition allows for validating decoded query parameters that conform to the Content protocol.
And the following URL,
http://localhost:8080/model?name=Vapor
, you can now validate the query parameter "name" as follows:The existing content validation method
validate(_:)
has been renamed tovalidate(content:)
to reduce ambiguity.